package com.fauks.restful.bean;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * 获取Spring IOC容器(Aware)
 */
@Component
public class CustomApplicationContextAware implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        //获取Spring本身上下文
        CustomApplicationContextAware.applicationContext = applicationContext;
    }

    public int getBeanCount() {
        return applicationContext.getBeanDefinitionCount();
    }

    public String[] getBeanName() {
        return applicationContext.getBeanDefinitionNames();
    }
}
